﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;
using ECCIT;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.IDAL;
using OgilvyOne.UKNow.DALFactory;

namespace OgilvyOne.UKNow.DAL.Test
{
    [TestFixture]
    [Category("")]
    public class ArtFormDALTest
    {
        private ArtFormModel CreateNewModel()
        {
            ArtFormModel model = new ArtFormModel();
            model.ID = null;
            model.LanguageID = 1033;
            model.Name = "Design";
            model.Order = 1;
            model.ShortDescription = "Design";
            model.Detail = "This is the art form: Design";

            return model;
        }

        [Test]
        public void TestSaveInsert()
        {
            ArtFormModel model = CreateNewModel();
            IDALArtForm dal = ArtFormDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);
                Assert.AreNotEqual(null, result.ReturnObject);
                Assert.AreNotEqual(0, ((ArtFormModel)result.ReturnObject).ID);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestSaveInsert failed with exception: " + ex.Message);
            }
        }

        [Test]
        public void TestSaveUpdate()
        {
            ArtFormModel model = CreateNewModel();
            IDALArtForm dal = ArtFormDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);

                model.Detail = "This is updated";
                result = dal.Save(model);
                Assert.AreEqual(true, result.Result);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestSaveUpdate failed with exception: " + ex.Message);
            }
        }

        [Test]
        public void TestGetArtFormModelByID()
        {
            ArtFormModel model = CreateNewModel();
            IDALArtForm dal = ArtFormDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);

                ArtFormModel retrievedModel = dal.GetArtFormModelByID(model.ID);
                Assert.AreNotEqual(null, retrievedModel);
                Assert.AreEqual(model.ID, retrievedModel.ID);
                Assert.AreEqual(model.Name, retrievedModel.Name);
                Assert.AreEqual(model.ShortDescription, retrievedModel.ShortDescription);
                Assert.AreEqual(model.Order, retrievedModel.Order);
                Assert.AreEqual(model.Detail, retrievedModel.Detail);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestGetArtFormModelByID failed with exception: " + ex.Message);
            }
        }

        [Test]
        public void TestDelete()
        {
            ArtFormModel model = CreateNewModel();
            IDALArtForm dal = ArtFormDALFactory.Create(1033);
            try
            {
                ResultInfo result = dal.Save(model);
                Assert.AreEqual(true, result.Result);

                IList<int?> idList = new List<int?>();
                idList.Add(model.ID);
                result = dal.Delete(idList);
                Assert.AreEqual(true, result.Result);
            }
            catch (Exception ex)
            {
                Assert.Fail("Test: TestDelete failed with exception: " + ex.Message);
            }
        }
    }
}
